package com.itlong.cloud.app.resource;

import com.itlong.cloud.POJO.VO.app.engineer.AppEngineerUserInfoVO;
import com.itlong.cloud.POJO.VO.app.engineer.AppEngineerUserOwnProjectVO;
import com.itlong.cloud.app.service.IAppEngineerService;
import com.itlong.cloud.user.app.IAppEngineerServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <desc>
 *      工程版APP接口暴露实现类。
 * <desc/>
 *
 * @createDate 2017/11/6.
 */
@RestController
public class AppEngineerServiceResource implements IAppEngineerServiceClient {

    @Autowired
    IAppEngineerService iAppEngineerService; //工程版APP登录


    /**
     * <desc>
     *     记录APP端用户登录信息
     * </desc>
     * @param userInfoPO
     * @return
     * @author shengen.T
     * @throws Exception
     * @createDate 2017/11/6
     */
    @Override
    @RequestMapping(path = "/engineer/logEngineerLogin",method = RequestMethod.POST)
    public AppEngineerUserInfoVO logEngineerLoginInfo(@RequestBody AppEngineerUserInfoVO userInfoPO) throws  Exception{
        return iAppEngineerService.logEngineerLoginInfo(userInfoPO);
    }

    /**
     * <desc>
     *      获取工程版APP登录信息。
     * <desc/>
     *
     * @param  phoneNo 工程人员账号
     * @return
     * @author shengen.T
     * @createDate 2018-01-20
     */
    @Override
    @RequestMapping(path = "/engineer/getUserInfoByPhoneNo",method = RequestMethod.POST)
    public AppEngineerUserInfoVO getEngineerAppUserLogin(@RequestParam("phoneNo") String phoneNo) throws Exception{
         return  iAppEngineerService.getEngineerAppUserLogin(phoneNo);
    }

    /**
     * <desc>
     *      验证工程账号权限信息。
     * <desc/>
     *
     * @param  userId 用户ID
     * @return
     * @author shengen.T
     * @createDate 2018-01-20
     */
    @Override
    @RequestMapping(path = "/engineer/checkEngineerAuth",method = RequestMethod.POST)
    public Integer checkEngineerLogin(@RequestParam("userId") String userId) throws Exception{
        return iAppEngineerService.checkEngineerLogin(userId);
    }


    /**
     * <desc>
     *     APP端登录获取用户项目列表信息
     * </desc>
     *
     * @param userId  用户ID
     * @return  APP用户所拥有的项目配置信息的集合
     * @author shengen.T
     * @createDate 2017/11/6
     */
    @Override
    @RequestMapping(path = "/engineer/getUserOwnProjectsInfo",method = RequestMethod.POST)
    public List<AppEngineerUserOwnProjectVO> getUserOwnProjectsInfo(@RequestParam("userId") String userId) throws  Exception{
        return iAppEngineerService.getUserOwnProjectInfo(userId);
    }

    /**
     * <desc>
     *      从缓存获取用户信息
     * </desc>
     *
     * @param token
     * @return
     * @author shengen.T
     * @createDate 2017/11/8
     */
    @Override
    @RequestMapping(path = "/engineer/retrieve")
    public AppEngineerUserInfoVO retrieve(@RequestParam("token")String token)  throws  Exception {
        return iAppEngineerService.retrieve(token);
    }

    /**
     * <desc>
     *     工程版APP,更新密码
     * </desc>
     * @param userId
     * @param oldPswd 加密后的旧密码
     * @param currentPswd 加密后的新密码
     * @return
     * @author shengen.T
     * @createDate 2017/10/11
     */
    @Override
    @RequestMapping(path = "/engineer/updatePswd",method = RequestMethod.POST)
    public Integer updatePswd(@RequestParam("userId") String userId,
                               @RequestParam("oldPswd") String oldPswd,
                               @RequestParam("currentPswd") String currentPswd) throws Exception{
        return iAppEngineerService.updatePswd(userId,oldPswd,currentPswd);
    }

}
